<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var r =""
        var n = prompt("输入层数")
        level=parseInt(n)

    for(i=1;i<=level;i++)
    {
        //拼空格
        for(k=1;k<=level-i;k++)
        {
            r= r + " "
        }
        //拼*
        for(j=1;j<=i*2-1;j++)
        {
            r= r + "*"
        }
        r += "\n"
    }
    console.log(r)

    </script>
</body>
</html>